package guestbook;

import java.util.*;

import com.google.appengine.api.datastore.*;
import com.google.appengine.repackaged.com.google.common.collect.*;

public class LDatastoreService implements DatastoreService
{
	private DatastoreService ds;
	public Context context;

	public void tally(String method)
	{
		context.tally.tallyCall(method);
	}

	public LDatastoreService(DatastoreService bds, Context context)
	{
		this.ds = bds;
		this.context = context;
	}

	public KeyRange allocateIds(Key parent, java.lang.String kind, long num)
	{
		if (Tally.ON)
			tally("allocateIds");

		return ds.allocateIds(parent, kind, num);
	}

	public KeyRange allocateIds(java.lang.String kind, long num)
	{
		if (Tally.ON)
			tally("allocateIds");

		return ds.allocateIds(kind, num);
	}

	@Override
	public KeyRangeState allocateIdRange(KeyRange range)
	{
		if (Tally.ON)
			tally("allocateIdRange");

		return ds.allocateIdRange(range);
	}

	public Transaction beginTransaction()
	{
		if (Tally.ON)
			tally("beginTransaction");

		return ds.beginTransaction();
	}

	public void delete(java.lang.Iterable<Key> keys)
	{
		if (Tally.ON)
			tally("delete[]");

		ds.delete(keys);
	}

	public void delete(Key... keys)
	{
		if (Tally.ON)
			tally("delete[]");

		ds.delete(keys);
	}

	public void delete(Transaction txn, java.lang.Iterable<Key> keys)
	{
		if (Tally.ON)
			tally("delete[]");
		
		ds.delete(txn, keys);
	}

	public void delete(Transaction txn, Key... keys)
	{
		if (Tally.ON)
			tally("delete[]");

		ds.delete(txn, keys);
	}

	public Map<Key, Entity> get(java.lang.Iterable<Key> keys)
	{
		if (Tally.ON)
			tally("get[]");

		return ds.get(keys);
	}

	public Entity get(Key key) throws EntityNotFoundException
	{
		if (Tally.ON)
			tally("get");

		return ds.get(key);
	}

	public java.util.Map<Key, Entity> get(Transaction txn, java.lang.Iterable<Key> keys)
	{
		if (Tally.ON)
			tally("get[]");

		return ds.get(txn, keys);
	}

	public Entity get(Transaction txn, Key key) throws EntityNotFoundException
	{
		if (Tally.ON)
			tally("get");
		
		return ds.get(txn, key);
	}

	public java.util.Collection<Transaction> getActiveTransactions()
	{
		if (Tally.ON)
			tally("getActiveTransactions");
		
		return ds.getActiveTransactions();
	}

	public Transaction getCurrentTransaction()
	{
		if (Tally.ON)
			tally("getCurrentTransaction");

		return ds.getCurrentTransaction();
	}

	public Transaction getCurrentTransaction(Transaction returnedIfNoTxn)
	{
		if (Tally.ON)
			tally("getCurrentTransaction");

		return ds.getCurrentTransaction(returnedIfNoTxn);
	}

	public LPreparedQuery prepare(Query query)
	{
		if (Tally.ON)
			tally("prepare");

		return new LPreparedQuery(ds.prepare(query), context, query);
	}

	public PreparedQuery prepare(Transaction txn, Query query)
	{
		if (Tally.ON)
			tally("prepare");

		return new LPreparedQuery(ds.prepare(txn, query), context, query);
	}

	public Key put(Entity entity)
	{
		if (Tally.ON)
			tally((entity.getKey().isComplete() ? "update" : "put") + "-" + entity.getKind());

		context.putHelper.put(entity);
		return ds.put(entity);
	}

	public Key put(Transaction txn, Entity entity)
	{
		if (Tally.ON)
			tally((entity.getKey().isComplete() ? "update" : "put") + "-" + entity.getKind());

		context.putHelper.put(entity);
		return ds.put(txn, entity);
	}

	public java.util.List<Key> put(Transaction txn, java.lang.Iterable<Entity> entities)
	{
		if (Tally.ON)
			tally("put[]");

		context.putHelper.put(entities);
		return ds.put(txn, entities);
	}

	@Override
	public List<Key> put(Iterable<Entity> entities)
	{
		if (Tally.ON)
			tally("put[]");
		
		context.putHelper.put(entities);
		return ds.put(entities);
	}
	@Override
	public DatastoreAttributes getDatastoreAttributes()
	{
		return ds.getDatastoreAttributes();
	}
}
